package com.example.intelligentattendancesystem.controller;


import com.example.intelligentattendancesystem.mapping.UserMapping;
import com.example.intelligentattendancesystem.pojo.User;
import com.example.intelligentattendancesystem.service.FileUpService;
import com.example.intelligentattendancesystem.service.IndexService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;

/**
 * 处理登录登出与注册的类
 * @author
 * @version 1.0
 * @className indexController
 * @since 1.0
 */
@RestController
@RequestMapping("smartAttendance/index")
public class IndexController {
    @Autowired
    UserMapping userMapping;



    @Autowired
    IndexService indexService;
    /**
     * 登录
     * @param userId
     * @param password
     * @return 登录失败返回null，成功返回user
     */
    @RequestMapping("/login")
    public User login(int userId,String password){
        User user = indexService.loginService(userId, password);
        return user;
    }

    /**
     * 登出
     * @param userId
     */
    @RequestMapping("/logout")
    public void logout(HttpSession session, String userId){
        session.removeAttribute(userId);
    }
    /**
     * 注册
     * @param user
     * @return 成功返回true失败false
     */
    @RequestMapping("/register")
    public Boolean register(User user){
//        System.out.println("正在注册："+user);
        boolean register = indexService.registerService(user);
//        System.out.println(register);
        return register;
    }
}
